package application.common.util;

public class CmdUtil {
	
	public static final int OPEN=0;
	public static final int STATUS_OPEN=1;
	public static final int INFRARED=2;
	
	public static byte[] getOpen(int iLCK, int iBOARD) {
		return getCmd( OPEN,  iLCK,  iBOARD);
	}
	
	public static byte[] getOpenStatus(int iLCK, int iBOARD) {
		return getCmd( STATUS_OPEN,  iLCK,  iBOARD);
	}
	
	public static byte[] getSaveStatus(int iLCK, int iBOARD) {
		return getCmd( INFRARED,  iLCK,  iBOARD);
	}
	
	public static byte[] getCmd(int cmdType, int iLCK, int iBOARD) {
		byte[] bcmd = new byte[8];
		switch (cmdType) {
		case OPEN:// 成功返回一样的代码
			bcmd[0] = (byte) 0xAA;// head
			bcmd[1] = (byte)iBOARD;// boardNO
			bcmd[2] = 0x01;// command
			bcmd[3] = 0x00;// empty
			bcmd[4] = 0x00;// empty
			bcmd[5] = (byte)iLCK;// openNO
			bcmd[6] = (byte)(bcmd[1] ^ bcmd[2] ^ bcmd[3] ^ bcmd[4] ^ bcmd[5]);// XOR
			bcmd[7] = 0x55;// END
			break;
		case STATUS_OPEN:
			bcmd[0] = (byte) 0xAA;
			bcmd[1] = (byte)iBOARD;
			bcmd[2] = 0x02;
			bcmd[3] = 0x00;
			bcmd[4] = 0x00;
			bcmd[5] = (byte)iLCK;
			bcmd[6] = (byte)(bcmd[1] ^ bcmd[2] ^ bcmd[3] ^ bcmd[4] ^ bcmd[5]);
			bcmd[7] = 0x55;
			break;
		case INFRARED:
			bcmd[0] = (byte)0xAA;
			bcmd[1] = (byte)iBOARD;
			bcmd[2] = 0x03;
			bcmd[3] = 0x00;
			bcmd[4] = 0x00;
			bcmd[5] = (byte)iLCK;
			bcmd[6] = (byte)(bcmd[1] ^ bcmd[2] ^ bcmd[3] ^ bcmd[4] ^ bcmd[5]);
			bcmd[7] = 0x55;
			break;
		}
		return bcmd;
	}
	
	
}
